﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>流程事件类</title>
    <meta charset="UTF-8" />
    <title>节点-事件</title>
    <script src="../../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>

    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />

    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../../Scripts/config.js"></script>
    <script type="text/javascript" src="../../Comm/Gener.js"></script>

    <script type="text/javascript">
        //页面启动函数.
        $(function () {

            $("#Msg").html("正在加载,请稍后......");

            //事件类型.
            GenerBindEnumKey("DDL_DoType", "EventDoType", "0");

            var fk_Event = GetQueryString("FK_Event");
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_CCFormDesigner_FrmEvent");
            handler.AddUrlData();

            var data = handler.DoMethodReturnString("ActionDtl_Init");
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }
            data = JSON.parse(data);

            // 业务单元
            var buess = data["BuessUnits"];
            GenerBindDDL("DDL_DoDoc", buess, "No", "Name", "");

            var ens = new Entities("BP.Sys.FrmEvents"); //查询.
            ens.Retrieve("FK_MapData", GetQueryString("FK_MapData"));

            for (var i = 0; i < ens.length; i++) {

                var en = ens[i];

                var newRow = "<tr>";
                newRow = "<tr ><td class=Idx>" + i + "</td>";
                newRow += "<td>" + en.FK_Event + "</td>";

                newRow += "<td>" + GetDoType(en.DoType) + "</td>";
                newRow += "<td>" + en.DoDoc + "</td>";
                newRow += "<td>" + en.MsgOK + "</td>";
                newRow += "<td>" + en.MsgError + "</td>";
                newRow += "<td>";
                newRow += "<a href=\"javascript:Delete('" + en.MyPK + "')\"><img src='/WF/Img/Btn/Delete.gif' border=0 />删除</a>";
                newRow += "<a href=\"javascript:Edit('" + en.MyPK + "')\"><img src='/WF/Img/Btn/Edit.gif' border=0 />编辑</a>";
                newRow += "</td>";
                newRow += "</tr>";

                $("#Table1 tr:last").after(newRow);
            }

        });

        function GetDoType(doType) {

            var cfg = "@0=禁用@1=执行存储过程@2=执行SQL语句@3=执行URL@4=WebServices(未完成)@5=执行ddl文件的类与方法@6=EventBase类@7=业务单元";

            var cfgs = cfg.split('@');

            for (var i = 0; i < cfgs.length; i++) {
                var vss = cfgs[i];
                if (vss.indexOf('=') == -1)
                    continue;

                var vals = vss.split('=');

                if (vals[0] == doType)
                    return vals[1];
            }

            return doType + 'ss';
        }

        function Save() {

            var en = new Entity("BP.Sys.FrmEvent");
            en.CopyForm();
            en.CopyURL();
            en.MyPK = en.FK_MapData + "_" + en.FK_Event; //组合主键.
            en.RetrieveFromDBSources();
            en.CopyURL();
            en.CopyForm();

            if (en.DoType == 7) {
                var doc = document.getElementById("DDL_DoDoc").value;
                en.DoDoc = doc;
            } else {
                var doc = document.getElementById("TB_DoDoc").value;
                en.DoDoc = doc;
            }

            en.Save();

            //  alert("保存成功.");
            Reload();
        }

        //执行编辑.
        function Edit(mypk) {

            var en = new Entity("BP.Sys.FrmEvent");
            en.MyPK = mypk;
            en.RetrieveFromDBSources();
            GenerFullAllCtrlsVal(en);
        }

        //执行删除.
        function Delete(mypk) {

            if (confirm('您确定要删除' + mypk + '吗？') == false)
                return;

            var en = new Entity("BP.Sys.FrmEvent");
            en.MyPK = mypk;
            en.Delete();

            Reload();
        }
        function doChangeContent(o) {

            if ($(o).val() == "7") {

                document.getElementById("TB_DoDoc").disabled = "disabled";
                $("#DDL_DoDoc").show();
                document.getElementById("DDL_DoDoc").disabled = "";
                //$("#TB_DoDoc").hide();
                //
            } else {
                $("#TB_DoDoc").show();
                $("#DDL_DoDoc").hide();
            }
        }
    </script>
</head>
<body>

    <form id="cc">
        <table style="width:90%;" id="Table1">
            <caption>表单事件列表</caption>
            <tr>
                <th>IDX</th>
                <th>事件名称</th>
                <th>事件类型</th>
                <th>执行内容</th>
                <th>成功提示</th>
                <th>失败提示</th>
                <th>操作</th>
            </tr>
        </table>

        <br />
        <br />

        <fieldset>
            <legend>新增事件 </legend>
            <table style="width:80%;" id="Table2">
                <tr>
                    <td>事件类型</td>
                    <td>
                        <select id="DDL_FK_Event" name="DDL_FK_Event">
                            <option value="FrmLoadBefore"> 节点表单载入前</option>
                            <option value="FrmLoadAfter"> 节点表单载入后</option>
                            <option value="SaveBefore"> 当表单保存前</option>
                            <option value="SaveAfter"> 当表单保存后</option>

                        </select>
                    </td>
                </tr>


                <tr>
                    <td>事件类型</td>
                    <td><select id="DDL_DoType" name="DDL_DoType" onchange="doChangeContent(this)"></select></td>
                </tr>


                <tr>
                    <td colspan=2>执行内容</td>
                </tr>

                <tr>
                    <td colspan=2>
<textarea id="TB_DoDoc" name="TB_DoDoc" style="width:90%;"></textarea>	<!-- 其它事件 -->
                    </td>
                </tr>


                <tr>
                    <td>业务单元（对执行业务单元有效）</td>
                    <td>
                        <select id="DDL_DoDoc" name="DDL_DoDoc" style="none;"></select>	<!-- 业务单元 -->
                    </td>
                </tr>


                <tr>
                    <td colspan=2>
                        执行成功信息提示(可为空)
                        <input type="text" id="TB_MsgOK" name="TB_MsgOK" />
                    </td>
                </tr>

                <tr>
                    <td colspan=2>
                        执行失败时提示(可为空)
                        <input type="text" id="TB_MsgError" name="TB_MsgError" />
                    </td>
                </tr>
            </table>
        </fieldset>


        <input id="Btn_Save" name="Btn_Save" value="保存" onclick="Save();" type="button" />
        <!--
        <input id="Btn_Delete"  name="Btn_Delete" value="删除" onclick="Delete();"  type="button"  />
        -->
    </form>

    <fieldset>
        <legend>帮助</legend>
        <ul>
            <li>1. 支持ccbpm表达式,什么是bpm表达式,请参考. </li>
            <li>2. 支持 @PTable 表达式, 比如: UPDATE @PTable SET MyFile1='xxx' WHERE OID=@WorkID </li>
        </ul>
    </fieldset>

</body>
</html>
